const result = require("../config/hand")
class register {
    constructor(ctx, ...obj) {
        this.ctx = ctx
        this.obj = obj
        // console.log("obj", obj)
    }
// t
    Errunder() {
        let bvc = this.obj.indexOf(undefined)
        if (bvc != -1) {
            throw new result('参数格式错误', 400)
        }
    }
    // 校验手机格式问题
    Phone(mode, num) {
        let pho_let = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
        if (!pho_let.test(this.obj[num])) {
            throw new result(mode, 202)
        }
    }

    // 校验password
    Password(mode, num) {
        let pas_let = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{8,20}$/
        if (!pas_let.test(this.obj[num])) {
            throw new result(mode, 202)
        }
    }
    // 校验空数组
    Arrfun(list, num) {
        if (JSON.parse(this.obj[num].length === 0)) {
            throw new result(list, 202)
        }
    }
    // 校验空字符串 
    Parameter(list) {
        let bvc = this.obj.indexOf('')
        if (bvc != -1) {
            throw new result(list[bvc], 202)
        }
    }

    // 校验空格 t
    Blank(list) {
        let kong = this.obj.filter(item => {
            return item.split(" ").join("").length === 0
        })
        let bvc = this.obj.indexOf(kong[0])
        if (bvc != -1) {
            throw new result(list[bvc], 202)
        }
    }


}

// 注册校验
class regcheck extends register {
    start() {
        super.Errunder()
        super.Phone('请输入正确的手机号码!', 0)
        super.Password('密码校验!', 1)
    }

}
// 校验商家信息
class shoinfo extends register {
    startlist() {
        let arr = ['输入店铺名称', '请选择店铺地理位置', '请上传店铺头像']
        super.Errunder()
        super.Blank(arr)
        super.Parameter(arr)
        super.Arrfun('请上传头像',2)
    }
}


// 校验菜单添加
class putoncheck extends register {
    start() {
        let arr = ['请选择商品类目', '请输入商品名称', '请输入商品价格', '请选择商品单位', '请上传商品图片']
        // super.Errunder()
        super.Blank(arr) //校验空格
        super.Arrfun('请上传商品图片', 4) //校验空数组
    }
}





module.exports = {
    regcheck,
    shoinfo,
    putoncheck
}